package com.PVZ.view;

import com.PVZ.engine.map.GameMap;
import lombok.Data;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * Created by @Author: kabuda on @Date: 2021/5/19 11:10
 *
 * 绘制菜单 种子栏等
 */
@Data
public class ToolsBarView {

    private Graphics graphics;

    private final int maxMovement = 1400-GameFrame.WIDTH;

    /**
     * 当前地图移动方向 0:不动 1:右移 -1:左移
     */
    private int moveDirection = 0;

    private int curPosition = -100;

    /**
     * 每次移动的距离
     */
    private int moveDistance = 30;

    public ToolsBarView(Graphics graphics){
        this.graphics = graphics;
    }


    /**
     *  移动地图
     * @param direction 移动方向 1:向右 -1:向左
     * @return -1:向右移动中 0:移动结束 1:向右移动
     */
    public int moveMap(int direction){
        this.moveDirection = direction;

        if(direction==1){
            //指令向右移动地图
            curPosition += direction*moveDistance;

            if(curPosition>=this.maxMovement){
                this.moveDirection = 0;
                return 0;
            }
            return 1;
        }else if(direction==-1){
            //向左移动
            curPosition += direction*moveDistance;

            if(curPosition<=0){
                this.moveDirection = 0;
                return 0;
            }
            return -1;
        }
        return 0;
    }

}
